package com.kfm.base.string;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Arrays;

public class Demo04 {

    public static void main(String[] args) throws UnsupportedEncodingException {
        char[] chs = {'赵', '文', '翔', '七', '夕', '快', '乐'};
        String str = new String(chs, 3, 4);
        System.out.println(str);


        // 用系统默认编码
        System.out.println(Charset.defaultCharset());

        // 自定义编码
        Charset charset = Charset.forName("gbk");// gbk 编码对象
//        charset = StandardCharsets.UTF_8;
//        byte[] bytes = "情人节杀人案".getBytes("gbk");
        byte[] bytes = "情人节杀人案".getBytes(charset);
        System.out.println(Arrays.toString(bytes));

        // 默认编码
        str = new String(bytes, charset);
        System.out.println(str);

        int a = Character.codePointAt(new char[]{'A'}, 0);
        System.out.println(a);

        str = new String(new int[]{65, 66, 67, 68}, 0, 4);
        System.out.println(str);
    }
}
